import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDMail {
	/**id*/
	id,
	/**标题0.表示直接读取标题1.读取参数1*/
	addresserType,
	/**发件人*/
	addresser,
	/**标题*/
	title,
	/**内容*/
	content,
	/**掉落奖励*/
	drop,
	/**参数类型--1：世界boss排名--2：竞技场排名--3：军团讨伐排名--不填无识别参数*/
	paramType,
	/**强制系统邮件--0或不填：非强制--1：强制*/
	mandatoryReading,

	/**枚举数量*/
	EnumCount
}



export class CDMail{
	/**id*/
	public id: number;
	/**标题0.表示直接读取标题1.读取参数1*/
	public addresserType: number;
	/**发件人*/
	public addresser: number;
	/**标题*/
	public title: number;
	/**内容*/
	public content: number;
	/**掉落奖励*/
	public drop: number;
	/**参数类型--1：世界boss排名--2：竞技场排名--3：军团讨伐排名--不填无识别参数*/
	public paramType: number;
	/**强制系统邮件--0或不填：非强制--1：强制*/
	public mandatoryReading: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDMail.id: return this.id;
			case E_CDMail.addresserType: return this.addresserType;
			case E_CDMail.addresser: return this.addresser;
			case E_CDMail.title: return this.title;
			case E_CDMail.content: return this.content;
			case E_CDMail.drop: return this.drop;
			case E_CDMail.paramType: return this.paramType;
			case E_CDMail.mandatoryReading: return this.mandatoryReading;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDMail.id: this.id = v; break;
			case E_CDMail.addresserType: this.addresserType = v; break;
			case E_CDMail.addresser: this.addresser = v; break;
			case E_CDMail.title: this.title = v; break;
			case E_CDMail.content: this.content = v; break;
			case E_CDMail.drop: this.drop = v; break;
			case E_CDMail.paramType: this.paramType = v; break;
			case E_CDMail.mandatoryReading: this.mandatoryReading = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDMail> = new HashMap<number, CDMail>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDMail[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDMail();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].addresserType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].addresser = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].title = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].content = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].drop = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].paramType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].mandatoryReading = byte.readInt8();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDMail{
		return this.datas ? this.datas.get(id) : null;
	}
}
